package com.gxa.utils;

import com.gxa.common.exception.ValidateAppointmentSettingVoException;
import com.gxa.common.vo.AppointmentPageRequest;
import com.gxa.common.vo.AppointmentSettingVo;

/**
 * 验证某些数据是否符合规范，防止空参数等
 *
 * @author MacieSerenity
 */
public class ValidateUtils {

    /**
     * 空字符串
     */
    public static String NULL_STRING = "";

    /**
     * 验证AppointmentSettingVo中的数据是否有问题，有问题返回false
     * 验证成功返回true
     *
     * @param appointmentSettingVo 需要验证的实体类
     * @param validateId           是否要验证ID为非空，true 验证，false 不验证
     * @return 验证结果
     * @throws ValidateAppointmentSettingVoException 验证失败
     */
    public static void validateAppointmentSettingVo(AppointmentSettingVo appointmentSettingVo, boolean validateId,boolean validateUserID) throws ValidateAppointmentSettingVoException {
        if (validateId) {
            //ID不能为空
            if (appointmentSettingVo.getId() == null) {
                throw new ValidateAppointmentSettingVoException("ID为空，验证失败");
            }
        }
        if (validateUserID){
            if (appointmentSettingVo.getUserId() == null) {
                throw new ValidateAppointmentSettingVoException("UserId为空，验证失败");
            }
        }
        if (appointmentSettingVo.getDay() == null || appointmentSettingVo.getDay() < 1) {
            throw new ValidateAppointmentSettingVoException("Day为空或者Day小于1，验证失败");
        }
        if (appointmentSettingVo.getNumberLimit() == null || appointmentSettingVo.getNumberLimit() < 1) {
            throw new ValidateAppointmentSettingVoException("NumberLimit为空或者小于1，验证失败");
        }
        if (appointmentSettingVo.getStatus() == null) {
            throw new ValidateAppointmentSettingVoException("Status为空，验证失败");
        }
        byte b = appointmentSettingVo.getStatus();
        if ((b != 0) & (b != 1)) {
            throw new ValidateAppointmentSettingVoException("Status不是0或者1，验证失败");
        }
    }


}
